package com.wgh.product.service.impl;

import com.wgh.product.entity.shop.Category;
import com.wgh.product.mapper.CategoryMapper;
import com.wgh.product.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 分类Service实现类
 * 
 * @author AI Shop
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public List<Category> getCategoryTree() {
        return baseMapper.selectCategoryTree();
    }

    @Override
    public List<Category> getSubCategories(Long parentId) {
        return baseMapper.selectByParentId(parentId);
    }

    @Override
    public List<Category> getCategoriesByLevel(Integer level) {
        return baseMapper.selectByLevel(level);
    }

    @Override
    public List<Category> getEnabledCategories() {
        return baseMapper.selectEnabledCategories();
    }

    @Override
    public List<Long> getCategoryIdsWithChildren(Long id) {
        return baseMapper.selectCategoryIdsWithChildren(id);
    }

    @Override
    public Category getCategoryByName(String name) {
        return baseMapper.selectByName(name);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateStatusBatch(List<Long> ids, Integer status) {
        return baseMapper.updateStatusBatch(ids, status) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean addCategory(Category category) {
        return this.save(category);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateCategory(Category category) {
        return this.updateById(category);
    }
}